package com.hcmus.arLocation;

import com.hcmus.armobile.R;

import android.R.string;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

public class GetDirectionOption extends AugmentedActivity{

	private static String lonTo = "";
	private static String latTo = "";
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.directionlayout);
        Bundle extras = getIntent().getExtras();
        String value = "";
		if (extras != null) {
			
			value = extras.getString("location_name_to");
			lonTo = extras.getString("location_lon_to");
			latTo = extras.getString("location_lat_to");
		}
		
		TextView textToLocationName = (TextView) findViewById(R.id.content_location_to);
		textToLocationName.setText(value);
		Button btnDriving = (Button) findViewById(R.id.btnDriving);
		btnDriving.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Location last = ARData.getCurrentLocation();
				String direction = "http://maps.google.com/maps?saddr=" + last.getLatitude() + "," + last.getLongitude() + "&daddr="+latTo+ "," + lonTo +"&directionsmode=driving";
				Uri uri= Uri.parse(direction);
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(intent);
				onResume();
			}
			
		});
		Button btnTransit = (Button) findViewById(R.id.btnTransit);
		btnTransit.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Location last = ARData.getCurrentLocation();
				String direction = "http://maps.google.com/maps?saddr=" + last.getLatitude() + "," + last.getLongitude() + "&daddr="+latTo+ "," + lonTo +"&directionsmode=transit";
				Uri uri= Uri.parse(direction);
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(intent);
			}
			
		});
		Button btnWalking = (Button) findViewById(R.id.btnWalking);
		btnWalking.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Location last = ARData.getCurrentLocation();
				String direction = "http://maps.google.com/maps?saddr=" + last.getLatitude() + "," + last.getLongitude() + "&daddr="+latTo+ "," + lonTo +"&directionsmode=walking";
				Uri uri= Uri.parse(direction);
				Intent intent = new Intent(Intent.ACTION_VIEW, uri);
				startActivity(intent);
			}
		});
		
		ImageButton btnBack = (ImageButton) findViewById(R.id.btnBackDirection);
		btnBack.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent in = new Intent(v.getContext(), DetailLocation.class);
				startActivity(in);
			}
			
		});
    }
	
	
}
